package com.kehao.leetcode.jzoffer;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author Kehao.Chen
 * @version 1.0
 * @date 2022/6/23 21:02
 */
public class JZSolution031 {
    private static class LRUCache {

        private LinkedHashMap<Integer,Integer> linkedHashMap;

        public LRUCache(int capacity) {
            linkedHashMap = new LinkedHashMap<Integer, Integer>(capacity,0.75f,true){
                @Override
                protected boolean removeEldestEntry(Map.Entry eldest) {
                    return this.size()>capacity;
                }
            };
        }

        public int get(int key) {
            Integer result = linkedHashMap.get(key);
            return result!=null?result:-1;
        }

        public void put(int key, int value) {
            linkedHashMap.put(key,value);
        }
    }
}
